package com.ych.modules.api.authorInfc.item.controller;

import com.alibaba.fastjson.JSONObject;
import com.ych.modules.api.authorInfc.item.entity.CarouselOrderCreateVo;
import com.ych.modules.base.dbEntity.TItemShowOrderEntity;
import com.ych.modules.base.service.ITUserInfoService;
import com.ych.modules.common.service.ItemShowOrderService;
import com.ych.utils.TLMap;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/3/1
 * Time: 15:15
 * Description:
 */
@RestController("apiItemShowOrderController")
@RequestMapping("/api/auth/item/show/order")
@Api(tags = {"API——项目展示订单相关"}, description = "API——项目展示订单相关")
public class ItemShowOrderController {
    @Autowired
    private ItemShowOrderService itemShowOrderService;
    @Autowired
    private ITUserInfoService itUserInfoService;
    @PostMapping("/orderCreate")
    @ApiOperation(value = "轮播/固定头条订单创建", notes = "轮播/固定头条订单创建")
    public R<String> orderCreate(@RequestBody CarouselOrderCreateVo createVo) {
        try {
            if (StringUtils.isBlank(createVo.getBusinessId())
                    || StringUtils.isBlank(createVo.getShowType())
                    || null == createVo.getPayAmount()) {
                throw new RuntimeException("必传参数为空");
            }
            //密码校验
            itUserInfoService.validatePayPassword(TLMap.getUserId(),createVo.getPassword());

            TItemShowOrderEntity orderEntity = JSONObject.parseObject(JSONObject.toJSONBytes(createVo), TItemShowOrderEntity.class);
            itemShowOrderService.orderCreate(orderEntity);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
